package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.co.FollowCo;
import com.engineering.elink.common.ResultType;
import com.engineering.elink.service.FollowService;
import com.engineering.elink.util.MapConvert;

@RestController
@RequestMapping("/api/follow")
@Api(value = "关注接口")
public class FollowController {

	@Autowired
	private FollowService followService;

	/**
	 * checkFollow 检查是否关注
	 * 
	 * @return true 关注 false 未关注
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/checkFollow", method = RequestMethod.GET)
	@ApiOperation(value = "查看是否关注")
	public Map<String, Object> checkFollow(
			@ApiParam(value = "关注用户ID", required = true) @RequestParam(value = "followUserId", required = true) String followUserId,
			HttpServletRequest request) {
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId = "";
		if (userInfo != null && userInfo.containsKey("userId")) {
			 userId = (String) userInfo.get("userId");
		}
		return MapConvert.getMap(ResultType.SUCCESS, followService.checkFollow(userId, followUserId));
	}

	/**
	 * 关注/取消关注
	 * 
	 * @param followUserId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/follow", method = RequestMethod.POST)
	@ApiOperation(value = "关注或取消关注")
	public Map<String, Object> follow(@ApiParam(value = "关注用户ID", required = true) @RequestParam(value = "followUserId", required = true)
	String followUserId,HttpServletRequest request) {
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		if (userInfo != null && userInfo.containsKey("userId")) {
			String userId = (String) userInfo.get("userId");
			if (followService.follow(userId, followUserId)) {
				return MapConvert.getMap(ResultType.SUCCESS);
			}
		}
		return MapConvert.getMap(ResultType.REQUEST_PARAMS_ERROR);
	}

	/**
	 * 获取关注列表
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getFollowList", method = RequestMethod.GET)
	@ApiOperation(value = "获取关注列表")
	public Map<String, Object> getFollowList(@ModelAttribute @Valid FollowCo followCo,HttpServletRequest request) {
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		if (userInfo != null && userInfo.containsKey("userId")) {
			String userId = (String) userInfo.get("userId");
			followCo.setUserId(userId);
			return MapConvert.getMap(ResultType.SUCCESS, followService.getFollowList(followCo));
		}
		return MapConvert.getMap(ResultType.REQUEST_PARAMS_ERROR);
	}

	/**
	 * 获取他人关注列表
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "/getOtherFollowList", method = RequestMethod.GET)
	@ApiOperation(value = "获取他人关注列表")
	public Map<String, Object> getOtherFollowList(@ModelAttribute @Valid FollowCo followCo) {
		return MapConvert.getMap(ResultType.SUCCESS, followService.getFollowList(followCo));
	}

	/**
	 * 获取粉丝列表
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getByFollowList", method = RequestMethod.GET)
	@ApiOperation(value = "获取粉丝列表")
	public Map<String, Object> getByFollowList(@ModelAttribute @Valid FollowCo followCo,HttpServletRequest request) {
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		if (userInfo != null && userInfo.containsKey("userId")) {
			String userId = (String) userInfo.get("userId");
			followCo.setFollowUserId(userId);
			return MapConvert.getMap(ResultType.SUCCESS, followService.getByFollowList(followCo));
		}
		return MapConvert.getMap(ResultType.REQUEST_PARAMS_ERROR);
	}

	/**
	 * 获取他人粉丝列表
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "/getOtherByFollowList", method = RequestMethod.GET)
	@ApiOperation(value = "获取他人关注列表")
	public Map<String, Object> getOtherByFollowList(@ModelAttribute @Valid FollowCo followCo) {
		followCo.setFollowUserId(followCo.getUserId());
		return MapConvert.getMap(ResultType.SUCCESS, followService.getByFollowList(followCo));
	}

	/**
	 * 获取互粉列表
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getBothFollowList", method = RequestMethod.GET)
	@ApiOperation(value = "获取互粉列表")
	public Map<String, Object> getBothFollowList(@ModelAttribute @Valid FollowCo followCo,HttpServletRequest request) {
		String userId = (String) ( (Map<String, Object>) request.getAttribute("userInfo")).get("userId");
		followCo.setFollowUserId(userId);
		return MapConvert.getMap(ResultType.SUCCESS, followService.getBothFollowList(followCo));
	}

	/**
	 * 获取他人粉丝列表
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "/getOtherBothFollowList", method = RequestMethod.GET)
	@ApiOperation(value = "获取他人互粉列表")
	public Map<String, Object> getOtherBothFollowList(@ModelAttribute @Valid FollowCo followCo) {
		followCo.setFollowUserId(followCo.getUserId());
		return MapConvert.getMap(ResultType.SUCCESS, followService.getBothFollowList(followCo));
	}

	/**
	 * 添加/删除企业精英（加精英表或者添加字段） 获取企业精英列表 修改企业信息 获取企业列表 新增企业访问记录 获取企业访问记录（内含点评次数）
	 * 各种底部 （意见反馈要加表） 个人中心 模块排列顺序 浏览记录 评论记录 视频转码 文件上传新增一个类别 个人发送接收消息 签到等
	 */
}
